home *** CD-ROM | disk | FTP | other *** search
/ Programming in Microsoft Windows with C# / Programacion en Microsoft Windows con C#.iso / Codigo / Trazados, regiones y recorte / ScribbleWithPath / ScribbleWithPath.cs next >
Encoding:
Text File  |  2002-07-15  |  1.7 KB  |  69 lines

  1. //-----------------------------------------------
  2. // ScribbleWithPath.cs ⌐ 2001 by Charles Petzold
  3. //-----------------------------------------------
  4. using System;
  5. using System.Drawing;
  6. using System.Drawing.Drawing2D;
  7. using System.Windows.Forms;
  8.  
  9. class ScribbleWithPath: Form
  10. {
  11.      GraphicsPath path;
  12.      bool         bTracking;
  13.      Point        ptLast;
  14.  
  15.      public static void Main()
  16.      {
  17.           Application.Run(new ScribbleWithPath());
  18.      }
  19.      public ScribbleWithPath()
  20.      {
  21.           Text = "Garabatos con trazado";
  22.           BackColor = SystemColors.Window;
  23.           ForeColor = SystemColors.WindowText;
  24.  
  25.                // Crear el trazado.
  26.  
  27.           path = new GraphicsPath();
  28.      }
  29.      protected override void OnMouseDown(MouseEventArgs mea)
  30.      {
  31.           if (mea.Button != MouseButtons.Left)
  32.                return;
  33.  
  34.           ptLast = new Point(mea.X, mea.Y);
  35.           bTracking = true;
  36.  
  37.                // Iniciar una figura.
  38.  
  39.           path.StartFigure();
  40.      }
  41.      protected override void OnMouseMove(MouseEventArgs mea)
  42.      {
  43.           if (!bTracking)
  44.                return;
  45.  
  46.           Point ptNew = new Point(mea.X, mea.Y);
  47.           
  48.           Graphics grfx = CreateGraphics();
  49.           grfx.DrawLine(new Pen(ForeColor), ptLast, ptNew);
  50.           grfx.Dispose();
  51.  
  52.                // A±adir una lφnea.
  53.  
  54.           path.AddLine(ptLast, ptNew);
  55.  
  56.           ptLast = ptNew;
  57.      }
  58.      protected override void OnMouseUp(MouseEventArgs mea)
  59.      {
  60.           bTracking = false;
  61.      }
  62.      protected override void OnPaint(PaintEventArgs pea)
  63.      {
  64.                // Dibujar el trazado.
  65.  
  66.           pea.Graphics.DrawPath(new Pen(ForeColor), path);
  67.      }
  68. }
  69.